package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.NewsCommend;
import cn.wolfcode.trip.base.query.NewsCommendQueryObject;
import cn.wolfcode.trip.base.query.NewsQueryObject;
import cn.wolfcode.trip.base.service.INewsCommendService;
import cn.wolfcode.trip.base.service.INewsService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("news")
public class NewsController {
    @Autowired
    private INewsService newsService;
    @Autowired
    private INewsCommendService newsCommendService;

    //获取所有资讯
    @GetMapping("/list")
    public Object list(Model model, NewsQueryObject qo) {
        qo.setOrderBy("n.release_time desc");
        return newsService.query(qo);
    }


    //获取所有推荐资讯
    @GetMapping("/commends")
    public Object commendsList(Model model, NewsCommendQueryObject qo) {
        qo.setState(1);
        qo.setOrderBy("nc.schedule desc");
        PageInfo<NewsCommend> query = newsCommendService.query(qo);
        return query;
    }

    //根据资讯id获取某个资讯的详细信息(包含内容)

    @GetMapping("/{NewsId}")
    public Object getNews(@PathVariable Long NewsId) {
        return newsService.getNews(NewsId);
    }

    //根据相关类型获取相同内容的资讯文章
    @GetMapping("")
    public Object getReferenceNews(NewsQueryObject qo) {
        qo.setOrderBy("release_time desc");
        return newsService.getReferenceNews(qo);
    }


}
